﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_UserData_52_CommunicationAddressS2
	{
		#region internal methods

		internal static byte[] GenerateBytes(UserData userData)
		{
			if (userData is UserData_52_CommunicationAddressS2)
			{
				UserData_52_CommunicationAddressS2 userData52 = userData as UserData_52_CommunicationAddressS2;
				return GenParse_UserData_AsciiBytes_Address.GenerateBytes(UserData.UserData52CommunicationAddressS2, userData52.GetCopyOfAsciiBytes(), userData52.RelativeAddress, UserData_52_CommunicationAddressS2.MaxNrOfChars);
			}

			// TODO handle error - wrong UserData type
			byte[] userDataBytes = null;

			return userDataBytes;
		}

		internal static bool ParseBytes(byte[] userDataBytes, out UserData userData52CommunicationAddressS2, out int consumedBytes)
		{
			userData52CommunicationAddressS2 = null;
			consumedBytes = 0;			
			byte[] asciiAddressBytes;
			bool relativeAddressFlag;

			bool bRetVal = GenParse_UserData_AsciiBytes_Address.ParseBytes(userDataBytes, UserData.UserData52CommunicationAddressS2, out asciiAddressBytes, out relativeAddressFlag, out consumedBytes);
			if (bRetVal)
			{
				userData52CommunicationAddressS2 = new UserData_52_CommunicationAddressS2(asciiAddressBytes, relativeAddressFlag);
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
